<?php
    require "sql.php";
    $data=array(
        array(
            'code'=>0    
        ),
        array(
            'code'=>1
        )
    );
    $old_pass=md5($_POST['old_pass']);
    $new_pass=md5($_POST['new_pass']);
    $str1="select * from user where email = '".$_COOKIE['email']."' and passwords = '".$old_pass."'";
    $str2="update user set passwords='".$new_pass."' where email = '".$_COOKIE['email']."'";
    $str3="insert into log(log_name,log_time,log_kind) values('".$_COOKIE['username']."','".date('Y-m-d H:i:s')."','修改密码')";
    $result=$conn->query($str1);
    if ($result->num_rows > 0) {
        $conn->query($str2);
        $conn->query($str3);
        echo json_encode($data[1]);
    }else{
        echo json_encode($data[0]);
        
    };
    $conn->close();
?>